package com.lanxin.oa.zc.dao.daoImpl;

import com.lanxin.base.BaseDaoImpl;
import com.lanxin.bean.ZcAsset;
import com.lanxin.bean.ZcAssetmoveapply;
import com.lanxin.bean.ZcAssetmovedetails;
import com.lanxin.oa.zc.dao.ZcYiDongDao;
import org.springframework.stereotype.Repository;

import java.util.Calendar;
import java.util.List;

@Repository
public class ZcYiDongDaoImpl extends BaseDaoImpl implements ZcYiDongDao {
    @Override
    public List<ZcAssetmoveapply> selectydzc(Integer empid) {
        return super.queryAll("select distinct zcyd from ZcAssetmoveapply zcyd left join fetch zcyd.lcid left join fetch zcyd.jcyidong left join fetch zcyd.empcj left join fetch zcyd.empsq left join fetch zcyd.dept where zcyd.creator="+empid+"  order by zcyd.createDate desc");
    }

    @Override
    public List selecttiaojian(String startDate, String endDate,Integer empid,Integer status) {
        String hql = "select distinct zcyd from ZcAssetmoveapply zcyd left join fetch zcyd.lcid left join fetch zcyd.jcyidong left join fetch zcyd.empcj left join fetch zcyd.empsq left join fetch zcyd.dept where zcyd.creator="+empid+"";

        if (startDate != null && !startDate.equals("")) {
            hql = hql + " and zcyd.createDate >= '" + startDate + "'";
        }
        if (endDate != null && !endDate.equals("")) {

            hql = hql + " and  zcyd.createDate <= '" + endDate + "' ";
        }
        if (status != null && !status.equals("")) {

            hql = hql + " and  zcyd.status = '" + status + "' ";
        }
        hql = hql + " order by zcyd.createDate desc";
        return queryAll(hql);
    }

    @Override
    public List selectflow() {
        return super.queryAll("from LcFlow");
    }

    @Override
    public List selectEmpByempName() {
        return super.queryAll("from ZzEmployee");
    }

    @Override
    public List selectDeptById() {
        return super.queryAll("from ZzDepartment");
    }

    @Override
    public List selectJcbaseByDd() {
        return super.queryAll("from JcBasicdatavalue jc where jc.type=3");
    }

    @Override
    public List selectJcbaseByYdYy() {
        return super.queryAll("from JcBasicdatavalue jc where jc.type=6");
    }

    @Override
    public Integer getZcYdInfoCount() {
        Calendar car = Calendar.getInstance();

        String currentDate =String.valueOf(car.get(Calendar.YEAR))+"-"+String.valueOf(car.get(Calendar.MONTH)+1)+"-"+String.valueOf(car.get(Calendar.DATE));
        System.out.println(currentDate);
        String hql = "select count(*) from ZcAssetmoveapply  where date_format(createDate,'%Y-%m-%d') = str_to_date('"+currentDate+"','%Y-%m-%d')";

        Integer row = Integer.valueOf(selectByHQL(hql).toString());
        return row;
    }

    @Override
    public List selectZcaset() {
        return super.queryAll("from ZcAsset");
    }

    @Override
    public ZcAsset selectZcasetkg(Integer oid) {
        return (ZcAsset)super.selectByHQL("select distinct zcset  from ZcAsset zcset left join fetch zcset.empkg left join fetch zcset.jcdd where zcset.oid="+oid);
    }

    @Override
    public List selectemp_dept(Integer deptid) {
            String hql="from ZzEmployee emp  where emp.deptid="+deptid+" and emp.state=1";
            return queryAll(hql);
    }

    @Override
    public ZcAssetmoveapply selectbyid(Integer oid) {
        return (ZcAssetmoveapply) super.selectByHQL("select distinct zcyd from ZcAssetmoveapply zcyd left join fetch zcyd.zcydmx where zcyd.oid="+oid);
    }

    @Override
    public List<ZcAssetmovedetails> selectmx(Integer oid) {
        return super.queryAll("from ZcAssetmovedetails zcmx where zcmx.parentid="+oid);
    }


}
